import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import postcssPxToViewport from "postcss-px-to-viewport";
import AutoImport from "unplugin-auto-import/vite";

// https://vitejs.dev/config/
export default defineConfig({
  // base:'/h5',
  // publicPath: './',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()]
    }),
    AutoImport({
      imports: ["vue", "vue-router"],
      dts: "src/auto-import.d.ts" // 路径下自动生成文件夹存放全局指令
    })
  ],
  css: {
    postcss: {
      plugins: [
        postcssPxToViewport({
          unitToConvert: "px",
          viewportWidth: 375,
          unitPrecision: 6,
          propList: ["*"],
          viewportUnit: "vw",
          fontViewportUnit: "vw",
          selectorBlackList: ["ignore-"],
          minPixelValue: 1,
          mediaQuery: true,
          replace: true,
          exclude: [/^(?!.*node_modules\/vant)/],
          landscape: false
        }),
        postcssPxToViewport({
          unitToConvert: "px",
          viewportWidth: 750,
          unitPrecision: 6,
          viewportUnit: "vw",
          fontViewportUnit: "vw",
          propList: ["*", "!border"],
          selectorBlackList: ["ignore-"],
          minPixelValue: 1,
          mediaQuery: true,
          replace: true,
          exclude: [/node_modules\/vant/i],
          include: [],
          landscape: false
        })
      ]
    }
  },
  resolve: {
    alias: {
      // 配置别名
      "@": path.resolve(__dirname, "src")
    }
  },
  server: {
    host: "0.0.0.0",
    port: 3039,
    proxy: {
      "/api": {
        target: "https://saas-eco-api.freeydch.com", // 后台服务器地址
        changeOrigin: true, // 是否允许不同源
        secure: false, // 支持https
        rewrite: (path) => path.replace(/^\/api/, "/api")
      }
    }
  }
});
